<?php
require_once("config.php");
require_once("CMySQL.php");

$client=$_GET["client"];
$numero=$_GET["numero"];

$dbName="";
if(isset($_GET["dossier"])) {
	$dbName=CMySQL::getInstance()->getDbNameFromDossier($_GET["dossier"]);
}

CMySQL::getInstance()->selectDb($dbName);

$sql="SELECT document, typeMime, fileName FROM documentsClient WHERE client=\"".$client."\" AND numero=".$numero;
$result=CMySQL::getInstance()->execQuery($sql);
if(!$result) {
	echo mysql_error($db);
}

$row=mysql_fetch_array($result);

header("Content-type: ".$row["typeMime"]);
header("Content-Disposition: attachement; filename=\"".$row["fileName"]."\"");

echo $row["document"];
?>
